﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Prepare.Domain;
using Prepare.Domain.Entities;
using Prepare.WebUI.Models;

namespace Prepare.WebUI.Controllers
{
    public class TestController : Controller
    {
        private IRepository<Test> repository;
        
        public int PageSize = 4;

        public TestController( IRepository<Test> testRepository)
        {
            repository = testRepository;
        }

        public ViewResult List(int page = 1)
        {
            TestsListViewModel viewModel = new TestsListViewModel
            {
                Tests = repository.GetAll()
                    .OrderBy(t => t.TestId)
                    .Skip((page - 1) * PageSize)
                    .Take(PageSize),
                    PagingInfo = new PagingInfo
                    {
                        CurrentPage = page,
                        ItemsPerPage = PageSize,
                        TotalItems = repository.GetAll().Count()
                    }
            };
            return View(viewModel);
        }

        public ActionResult Index()
        {
            return View();
        }
    }
}
